package com.bnz.controller;

import com.bnz.pojo.R;
import com.bnz.pojo.Student;
import com.bnz.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/student")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    //C查询
    @GetMapping("/list")
    public R list(){
       List<Student> students = studentService.findAll();
       return R.ok().data("list",students);
    }
    // 增加
    @PostMapping("/add")
    public R add(@RequestBody Student student){
        studentService.add( student);
        return R.ok();
    }
    //修改
    @PutMapping("/update")
    public R update(@RequestBody Student student){
        studentService.update(student);
        return R.ok().message("修改成");
    }
    //删除
    @DeleteMapping("/delete/{sid}")
    public R delete(@PathVariable Integer sid){
        studentService.delete(sid);
        return R.ok();
    }
}
